﻿using System;

using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace gpsmid_wince.util {
	class Logger {
		public const int FATAL = 1;
		public const int ERROR = 2;
		public const int INFO = 3;
		public const int DEBUG = 4;
		public const int TRACE = 5;

		//private static Logger inst;
#if(!PocketPC)
		private static LoggerForm fr;
#endif

		private int level;
		private string source;
		public static Logger getInstance(Object obj, int level) {
#if(!PocketPC)			
			if(fr==null) {
				fr = new LoggerForm();
				fr.Show();
			}
#endif			
			return new Logger(obj.ToString(), level);
		}

		private Logger(string classname, int level) {
			this.level = level;
			this.source = classname;
		}
#if(!PocketPC)
		public void info(string s) {
			if(level>=INFO)	fr.addLog("[info:"+source+"] "+s);
		}
		public void debug(string s) {
			if(level>=DEBUG)fr.addLog("[debug:"+source+"] "+s);
		}
		public void error(string s) {
			if(level>=ERROR)fr.addLog("[error:"+source+"] "+s);
		}

		public void trace(string s) {
			if(level>=TRACE)fr.addLog("[trace:"+source+"] "+s);
		}
#else
		public void info(string s) {
			//if(level>=INFO)	MessageBox.Show("[info] "+s);
		}
		public void debug(string s) {
			//if(level>=DEBUG)fr.addLog("[debug] "+s);
		}
		public void error(string s) {
			if(level>=ERROR)MessageBox.Show("[error:"+source+"] "+s);
		}

		public void trace(string s) {
			//if(level>=TRACE)fr.addLog("[trace] "+s);
		}
#endif
	}
}
